home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-23 | 15.9 KB | 700 lines | [TEXT/CWIE] |
- ///--------------------------------------------------------------------------------------
- // BlitPixie8Bit.c
- //
- // Ideas and code snippets contributed by:
- // Ben Sharpe, Brigham Stevens, Sean Callahan, Joe Britt and Tim Collins
- //
- // Portions are copyright: © 1991-94 Tony Myles
- //
- // Description: Implementation of BlitPixie8Bit - a fast 8-bit blitter
- ///--------------------------------------------------------------------------------------
-
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __QDOFFSCREEN__
- #include <QDOffscreen.h>
- #endif
-
- #ifndef __NSSPRITEWORLD8BITBLITTER__
- #include "NSSpriteWorld8BitBlitters.h"
- #endif
-
-
- #if GENERATINGPOWERPC
- ///--------------------------------------------------------------------------------------
- // BlitPixie8Bit
- ///--------------------------------------------------------------------------------------
- void BlitPixie8Bit(
- PixelChunkPtr srcPixelP,
- PixelChunkPtr dstPixelP,
- register unsigned long rowsToCopy,
- register unsigned long numBytesPerRow,
- register unsigned long srcOffset,
- register unsigned long dstOffset)
- {
- register long index;
- register PixelChunkPtr startSrcPixelP;
- register PixelChunkPtr startDstPixelP;
-
-
- startSrcPixelP = srcPixelP;
- startDstPixelP = dstPixelP;
-
- while (rowsToCopy--)
- {
- register fourblits = (numBytesPerRow >> 2);
-
- srcPixelP = startSrcPixelP;
- dstPixelP = startDstPixelP;
-
- for (index = 0; index < fourblits; index++)
- {
- register unsigned long temp1;
-
- temp1 = srcPixelP[index];
- dstPixelP[index] = temp1;
- }
- srcPixelP += fourblits;
- dstPixelP += fourblits;
- if (numBytesPerRow & 0x2)
- *((unsigned short *) dstPixelP)++ = *((unsigned short *) srcPixelP)++;
- if (numBytesPerRow & 0x1)
- *((unsigned char *)dstPixelP)++ = *((unsigned char *)srcPixelP)++;
-
- // bump to next row
- (char *)startSrcPixelP += srcOffset;
- (char *)startDstPixelP += dstOffset;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieMask8Bit
- ///--------------------------------------------------------------------------------------
-
- void BlitPixieMask8Bit(
- register PixelPtr srcPixelP,
- register PixelPtr dstPixelP,
- register PixelPtr maskPixelP,
- register unsigned long rowsToCopy,
- register unsigned long numBytesPerRow,
- register unsigned long srcOffset,
- register unsigned long dstOffset)
- {
- register long index;
- register PixelPtr startSrcPixelP;
- register PixelPtr startDstPixelP;
- register PixelPtr startMaskPixelP;
-
- startSrcPixelP = srcPixelP;
- startDstPixelP = dstPixelP;
- startMaskPixelP = maskPixelP;
-
- while (rowsToCopy--)
- {
- register fourblits = (numBytesPerRow >> 2);
-
- srcPixelP = startSrcPixelP;
- dstPixelP = startDstPixelP;
- maskPixelP = startMaskPixelP;
-
- for (index = 0; index < fourblits; index++)
- {
- register unsigned long temp1;
-
- temp1 = dstPixelP[index] & maskPixelP[index] | srcPixelP[index];
- dstPixelP[index] = temp1;
- }
- srcPixelP += fourblits;
- dstPixelP += fourblits;
- maskPixelP += fourblits;
- if (numBytesPerRow & 0x2)
- {
- register unsigned short temp1;
-
- temp1 = (*((unsigned short *) dstPixelP)) & (*((unsigned short *) maskPixelP)++) |
- *((unsigned short *) srcPixelP)++;
-
- (*((unsigned short *) dstPixelP)++) = temp1;
- }
- if (numBytesPerRow & 0x1)
- {
- register unsigned char temp1;
-
- temp1 = (*((unsigned char *) dstPixelP)) & (*((unsigned char *) maskPixelP)++) |
- *((unsigned char *) srcPixelP)++;
-
- (*((unsigned char *) dstPixelP)++) = temp1;
- }
-
- // bump to next row
- startSrcPixelP = (PixelPtr)(((char*)startSrcPixelP) + srcOffset);
- startDstPixelP = (PixelPtr)(((char*)startDstPixelP) + dstOffset);
- startMaskPixelP = (PixelPtr)(((char*)startMaskPixelP) + srcOffset);
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixiePartialMask8Bit
- ///--------------------------------------------------------------------------------------
-
- void BlitPixiePartialMask8Bit(
- register PixelPtr srcPixelP,
- register PixelPtr dstPixelP,
- register PixelPtr maskPixelP,
- register unsigned long rowsToCopy,
- register unsigned long numBytesPerRow,
- register unsigned long srcOffset,
- register unsigned long dstOffset)
- {
- register long index;
- register PixelPtr startSrcPixelP;
- register PixelPtr startDstPixelP;
- register PixelPtr startMaskPixelP;
-
- startSrcPixelP = srcPixelP;
- startDstPixelP = dstPixelP;
- startMaskPixelP = maskPixelP;
-
- while (rowsToCopy--)
- {
- register fourblits = (numBytesPerRow >> 2);
-
- srcPixelP = startSrcPixelP;
- dstPixelP = startDstPixelP;
- maskPixelP = startMaskPixelP;
-
- for (index = 0; index < fourblits; index++)
- {
- register unsigned long temp1;
-
- temp1 = dstPixelP[index] & maskPixelP[index] |
- ( (~maskPixelP[index])&srcPixelP[index]);
- dstPixelP[index] = temp1;
- }
- srcPixelP += fourblits;
- dstPixelP += fourblits;
- maskPixelP += fourblits;
- if (numBytesPerRow & 0x2)
- {
- register unsigned short temp1;
-
- temp1 = (*((unsigned short *) dstPixelP)) & (*((unsigned short *) maskPixelP)) |
- (~(*((unsigned short *) maskPixelP)++) &
- *((unsigned short *) srcPixelP)++);
-
- (*((unsigned short *) dstPixelP)++) = temp1;
- }
- if (numBytesPerRow & 0x1)
- {
- register unsigned char temp1;
-
- temp1 = (*((unsigned char *) dstPixelP)) & (*((unsigned char *) maskPixelP)) |
- (~(*((unsigned char *) maskPixelP)++) &
- *((unsigned char *) srcPixelP)++);
-
- (*((unsigned char *) dstPixelP)++) = temp1;
- }
-
- // bump to next row
- startSrcPixelP = (PixelPtr)(((char*)startSrcPixelP) + srcOffset);
- startDstPixelP = (PixelPtr)(((char*)startDstPixelP) + dstOffset);
- startMaskPixelP = (PixelPtr)(((char*)startMaskPixelP) + srcOffset);
- }
- }
-
-
- #else /* SW_USE_C */
-
- ///--------------------------------------------------------------------------------------
- // BlitPixie8Bit
- ///--------------------------------------------------------------------------------------
-
- asm void BlitPixie8Bit(
- register PixelPtr srcPixelP,
- register PixelPtr dstPixelP,
- register unsigned long rowsToCopy,
- register unsigned long numBytesPerRow,
- register unsigned long srcRowStride,
- register unsigned long dstRowStride)
- {
- register unsigned long loopsPerRow;
-
- machine 68020
-
- #if __MWERKS__
- fralloc +
- #endif
-
- sub.l numBytesPerRow, srcRowStride
- sub.l numBytesPerRow, dstRowStride
-
- // longWordsPerRow = numBytesPerRow >> 2;
- move.l numBytesPerRow, d0
- lsr.l #2, d0
-
- // numBytesPerRow -= longWordsPerRow << 2;
- move.l d0, d1
- lsl.l #2, d1
- sub.l d1, numBytesPerRow
-
- // loopsPerRow = longWordsPerRow >> 4;
- move.l d0, loopsPerRow
- lsr.l #4, loopsPerRow
-
- moveq #0xF, d1
- and.l d1, d0
- add.l d0, d0 // multiply longWordsPerRow by 2 (size of move.l (srcPixelP)+,(dstPixelP)+)
- lea @loopEnd, a0 // get address of the end of the loop
- suba.l d0, a0 // calculate where to jmp in the loop
-
- @forEachRow:
- move.l loopsPerRow, d0
- jmp (a0)
- @loopBase:
- move.l (srcPixelP)+, (dstPixelP)+ // 16
- move.l (srcPixelP)+, (dstPixelP)+ // 15
- move.l (srcPixelP)+, (dstPixelP)+ // 14
- move.l (srcPixelP)+, (dstPixelP)+ // 13
- move.l (srcPixelP)+, (dstPixelP)+ // 12
- move.l (srcPixelP)+, (dstPixelP)+ // 11
- move.l (srcPixelP)+, (dstPixelP)+ // 10
- move.l (srcPixelP)+, (dstPixelP)+ // 9
- move.l (srcPixelP)+, (dstPixelP)+ // 8
- move.l (srcPixelP)+, (dstPixelP)+ // 7
- move.l (srcPixelP)+, (dstPixelP)+ // 6
- move.l (srcPixelP)+, (dstPixelP)+ // 5
- move.l (srcPixelP)+, (dstPixelP)+ // 4
- move.l (srcPixelP)+, (dstPixelP)+ // 3
- move.l (srcPixelP)+, (dstPixelP)+ // 2
- move.l (srcPixelP)+, (dstPixelP)+ // 1
- @loopEnd:
- subq.l #1,d0
- bpl @loopBase
-
- // now do any leftover bits
- move.l numBytesPerRow, d0
- beq @nextRow
- subq.l #2, d0
- bmi @moveByte
- move.w (srcPixelP)+, (dstPixelP)+
- tst d0
- beq @nextRow
- @moveByte:
- move.b (srcPixelP)+, (dstPixelP)+
-
- @nextRow:
- adda.l srcRowStride, srcPixelP
- adda.l dstRowStride, dstPixelP
- subq.l #1, rowsToCopy
- bne @forEachRow
-
- #if __MWERKS__
- frfree
- #endif
-
- rts
- }
-
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieMask8Bit
- ///--------------------------------------------------------------------------------------
-
- asm void BlitPixieMask8Bit(
- register PixelPtr srcPixelP,
- register PixelPtr dstPixelP,
- register PixelPtr maskPixelP,
- register unsigned long rowsToCopy,
- register unsigned long numBytesPerRow,
- register unsigned long srcRowStride,
- register unsigned long dstRowStride)
- {
- register unsigned long loopsPerRow;
-
- machine 68020
-
- #if __MWERKS__
- fralloc +
- #endif
-
- sub.l numBytesPerRow, srcRowStride
- sub.l numBytesPerRow, dstRowStride
-
- // longWordsPerRow = numBytesPerRow >> 2;
- move.l numBytesPerRow, d0
- lsr.l #2, d0
-
- // numBytesPerRow -= longWordsPerRow << 2;
- move.l d0, d1
- lsl.l #2, d1
- sub.l d1, numBytesPerRow
-
- // loopsPerRow = longWordsPerRow >> 4;
- move.l d0, loopsPerRow
- lsr.l #4, loopsPerRow
-
-
- moveq #0xF, d1
- and.l d1, d0
- lsl.l #3, d0 // longWordsPerRow *= 8;
- lea @loopEnd, a0 // get address of the end of the loop
- sub.l d0, a0 // calculate where to jmp in the loop
-
- @forEachRow:
- move.l loopsPerRow, d2
- jmp (a0)
- @loopBase:
- // 16
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 15
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 14
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 13
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 12
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 11
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 10
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 9
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 8
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 7
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 6
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 5
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 4
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 3
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 2
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- // 1
- move.l (dstPixelP), d0
- and.l (maskPixelP)+, d0
- or.l (srcPixelP)+, d0
- move.l d0, (dstPixelP)+
- @loopEnd:
- subq.l #1, d2
- bpl @loopBase
-
- // now do any leftover bits
- move.l numBytesPerRow, d2
- beq @nextRow
- subq.l #2, d2
- bmi @moveByte
- move.w (dstPixelP), d0
- and.w (maskPixelP)+, d0
- or.w (srcPixelP)+, d0
- move.w d0, (dstPixelP)+
- tst d2
- beq @nextRow
- @moveByte:
- move.b (dstPixelP), d0
- and.b (maskPixelP)+, d0
- or.b (srcPixelP)+, d0
- move.b d0, (dstPixelP)+
-
- @nextRow:
- adda.l srcRowStride, srcPixelP
- adda.l srcRowStride, maskPixelP
- adda.l dstRowStride, dstPixelP
- subq.l #1, rowsToCopy
- bne @forEachRow
-
- #if __MWERKS__
- frfree
- #endif
-
- rts
- }
-
-
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixiePartialMask8Bit
- ///--------------------------------------------------------------------------------------
-
- asm void BlitPixiePartialMask8Bit(
- register PixelPtr srcPixelP,
- register PixelPtr dstPixelP,
- register PixelPtr maskPixelP,
- register unsigned long rowsToCopy,
- register unsigned long numBytesPerRow,
- register unsigned long srcRowStride,
- register unsigned long dstRowStride)
- {
- register unsigned long loopsPerRow;
-
- machine 68020
-
- #if __MWERKS__
- fralloc +
- #endif
-
- sub.l numBytesPerRow, srcRowStride
- sub.l numBytesPerRow, dstRowStride
-
- // longWordsPerRow = numBytesPerRow >> 2;
- move.l numBytesPerRow, d0
- lsr.l #2, d0
-
- // numBytesPerRow -= longWordsPerRow << 2;
- move.l d0, d1
- lsl.l #2, d1
- sub.l d1, numBytesPerRow
-
- // loopsPerRow = longWordsPerRow >> 4;
- move.l d0, loopsPerRow
- lsr.l #4, loopsPerRow
-
-
- moveq #0xF, d1
- and.l d1, d0
- mulu #14, d0 // longWordsPerRow *= 14 (bytes in segment of loop)
- lea @loopEnd, a0 // get address of the end of the loop
- sub.l d0, a0 // calculate where to jmp in the loop
-
- @forEachRow:
- move.l loopsPerRow, d2
- jmp (a0)
- @loopBase:
- // 16
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 15
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 14
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 13
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 12
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 11
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 10
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 9
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 8
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 7
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 6
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 5
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 4
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 3
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 2
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- // 1
- move.l (dstPixelP), d0
- and.l (maskPixelP), d0
- move.l (maskPixelP)+, d1
- not.l d1
- and.l (srcPixelP)+, d1
- or.l d1, d0
- move.l d0, (dstPixelP)+
- @loopEnd:
- subq.l #1, d2
- bpl @loopBase
-
- // now do any leftover bits
- move.l numBytesPerRow, d2
- beq @nextRow
- subq.l #2, d2
- bmi @moveByte
- move.w (dstPixelP), d0
- and.w (maskPixelP), d0
- move.w (maskPixelP)+, d1
- not.w d1
- and.w (srcPixelP)+, d1
- or.w d1, d0
- move.w d0, (dstPixelP)+
- tst d2
- beq @nextRow
- @moveByte:
- move.b (dstPixelP), d0
- and.b (maskPixelP), d0
- move.b (maskPixelP)+, d1
- not.b d1
- and.b (srcPixelP)+, d1
- or.b d1, d0
- move.b d0, (dstPixelP)+
-
- @nextRow:
- adda.l srcRowStride, srcPixelP
- adda.l srcRowStride, maskPixelP
- adda.l dstRowStride, dstPixelP
- subq.l #1, rowsToCopy
- bne @forEachRow
-
- #if __MWERKS__
- frfree
- #endif
-
- rts
- }
-
-
- #endif /* SW_USE_C */
-
-
-